﻿#region License

/*
 © 2012 Alex Kazaev
 * FolderDrive project [http://folderdrive.codeplex.com/]
 * Licensed under Ms-PL license [http://www.opensource.org/licenses/MS-PL]
 */

#endregion License

using System.Security.Permissions;
using Microsoft.Win32;

namespace FolderDrive.Core
{
  [RegistryPermission(SecurityAction.Demand, Write = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices")]
  public static class FolderDriveRegistry
  {
    const string KeyName = @"SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices";

    public static void CreateDrive(string letter, string path)
    {
      var key = Registry.LocalMachine.OpenSubKey(KeyName, true);
      key.SetValue(letter, @"\??\" + path, RegistryValueKind.String);
    }

    public static void DeleteDrive(string letter)
    {
      var key = Registry.LocalMachine.CreateSubKey(KeyName, RegistryKeyPermissionCheck.ReadWriteSubTree);
      key.DeleteValue(letter, false);
    }
  }
}